
class Service {
    constructor ($http, $q, $rootScope, $cookies, uiAlert) {
        "ngInject"
        return {
            request : (options) => {

                options = angular.extend({}, options);

                let def = $q.defer(), queryUri = "", params, $uiAlert;

                if (__DEBUG__) {
                    queryUri = "/ctg-sysmgr-permission-demo"
                } else {
                    queryUri = "/ctg-sysmgr-permission-demo"
                }

                if (options.host) queryUri = options.host;

                params = {
                    method: options.method || "GET",
                    url: queryUri + options.url,
                    params: options.params || ''
                }

                if ( options.method == "POST" ) {
                    angular.extend(params, {
                        data: $.param(options.data),
                        headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
                    })
                }

                $http(params).success( (data) => {
                    if (data.resultCode === '200') {
                        def.resolve(data);
                    } else {
                        def.reject(data);
                    }
                }).error( (data) => {
                    //data.resultMsg = '';
                    def.reject(data);
                });
                return def.promise;
            }
        }
    }
    static factory($http, $q) {
        "ngInject"
        return new Service($http, $q)
    }
}

export default Service;